<?php
namespace app\index\controller;
use app\index\model\Article as articleList;
class Article extends Common
{
    public function index(){
        $id=input('cateid');
        $res=new articleList();
        $cateRes=$res->getArticles($id);
        $page=$res->getArticles($id)->render();
        $this->assign('page', $page);
        $this->assign('articles',$cateRes);
        return view('article/index');
    }
    public function detail(){
        $id=input('id');
        $article=db('article')->where('id',$id)->find();
        $this->assign('article',$article);
        return view("article");
    }
    public function singlePage(){
        $id=input('pageid');
        $article=db('article')->where('cateid',$id)->select();
        $time=0;
        if($article){
            foreach ($article as $k=>$v){
                if(strtotime($v['date'])>$time){
                    $tid=$v['id'];
                    $time=strtotime($v['date']);
                }
            }
            $single=db('article')->where('id',$tid)->find();
        }else{
            $single=null;
        }

        $this->assign('article',$single);
        return view('article');
    }
}